package com.example.mysmall.mvp_rajava.ui.modules.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.mysmall.mvp_rajava.R;
import com.example.mysmall.mvp_rajava.entity.LiveChina;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by xingge on 2017/8/15.
 */

public class HomeAdapter extends BaseAdapter {

    private List<LiveChina.LiveBean> live;
    private LayoutInflater inflater;
    private Context context;
    public HomeAdapter(Context context, List<LiveChina.LiveBean> live) {
        this.context = context;
        this.live = live;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return live.size();
    }

    @Override
    public Object getItem(int position) {
        return live.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.home_listview_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        LiveChina.LiveBean liveBean = live.get(position);
        holder.mTitle.setText(liveBean.getTitle());
        Glide.with(context).load(liveBean.getImage()).into(holder.mImg);
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.mImg)
        ImageView mImg;
        @BindView(R.id.mTitle)
        TextView mTitle;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
